const { stringify } = require("querystring");
const { Database } = require("sqlite3");

function fullmark(){
    const sqlite3 = require("sqlite3").verbose()
    const path = require('path');
    const dbName = path.join(__dirname, '../data/demo.db');
    var db;
    db = new sqlite3.Database(dbName,function(err){
        if(err) throw err;
    })
    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=1 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=1 GROUP BY qone.c_id),2)  WHERE c_id=1`,function(err,row){
        if(err) throw err;
    })

    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=2 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=2 GROUP BY qone.c_id),2)  WHERE c_id=2`,function(err,row){
        if(err) throw err;
    })

    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=3 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=3 GROUP BY qone.c_id),2)  WHERE c_id=3`,function(err,row){
        if(err) throw err;
    })

    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=4 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=4 GROUP BY qone.c_id),2)  WHERE c_id=4`,function(err,row){
        if(err) throw err;
    })

    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=5 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=5 GROUP BY qone.c_id),2)  WHERE c_id=5`,function(err,row){
        if(err) throw err;
    })

    db.run(` UPDATE cafe SET  fullmark=ROUND((SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=6 AND score=10 GROUP BY qone.c_id)*1.0/(SELECT 
        COUNT(*)
        FROM qone WHERE qone.c_id=6 GROUP BY qone.c_id),2)  WHERE c_id=6`,function(err,row){
        if(err) throw err;
    })
}

module.exports=fullmark;